package com.bjpowernode.web;

import com.bjpowernode.entity.TClueRemark;
import com.bjpowernode.query.ClueRemarkQuery;
import com.bjpowernode.result.R;
import com.bjpowernode.service.TClueRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@RestController
@Slf4j
@RequestMapping("/api/clueRemark")
public class ClueRemarkController {

    @Resource
    private TClueRemarkService tClueRemarkService;

    // 保存备注方法
    @PostMapping("save")
    public R saveRemark(@Validated @RequestBody ClueRemarkQuery clueRemarkQuery ,
                        @RequestHeader(value = "Authorization") String jwt) {
        log.info("要保存的线索备注信息: {}" , clueRemarkQuery);
        clueRemarkQuery.setJwt(jwt);
        int save = tClueRemarkService.saveRemark(clueRemarkQuery);
        return save >= 1 ? R.OK() : R.FAIL();
    }

    @GetMapping("")
    public R clueByPage(@RequestParam(value = "id") Integer id,
                        @RequestParam(value = "current", defaultValue = "1") Integer current) {
        log.info("id : {}  ,  current {}", id, current);
        PageInfo<TClueRemark> tClueRemarkPageInfo = tClueRemarkService.getActivityByPage(id, current);
        log.info("值 : " + tClueRemarkPageInfo.getPageSize());
        return R.OK(tClueRemarkPageInfo);
    }

}
